﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
using Models.Common;
using Models.Device;
using Models.Task;
using Nancy.TinyIoc;
using Newtonsoft.Json;

using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Data;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using UtilsORM;
using UtilsORM.MySqlData;
using static Models.Common.EnumDeviceState;
using GatewayServerService.Data;
using UtilsBase;
using UtilsCache;
using FreeRedis;
using NetTaste;
using System.Net;
using Newtonsoft.Json.Linq;
using Models.WebClient;
using Models.SocketModel;

namespace GatewayServerService.CloudCenter
{
    /// <summary>
    /// 定时任务执行
    /// </summary>
    public class ServiceCloudRemoteManager
    {

        public async void sendMsgDeviceStatusChange(string dguid, string key, string value)
        {

            try
            {

                iot_device device = new DBIotDeviceCache().getClientDeviceByCache_60Min(dguid);
                if (device == null)
                {
                    return;
                }
                ViewDeviceCurrentValue viewDeviceCurrentValue = new ViewDeviceCurrentValue();
                viewDeviceCurrentValue.modelNo = device.d_p_model_no == null ? 0 : int.Parse(device.d_p_model_no.ToString());
                viewDeviceCurrentValue.key = key;
                viewDeviceCurrentValue.value = value;
                viewDeviceCurrentValue.addtime = DateTime.Now;
                string data = JsonConvert.SerializeObject(viewDeviceCurrentValue);
                UtilMemoryCacheHelper.set("deviceValue_" + (dguid + key).ToLower(), data, 60);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

        }

    }
}
